<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 12">
<meta name=Originator content="Microsoft Word 12">
<link rel=File-List href="basics_files/filelist.xml">
<title>C++Script Manual</title>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>calum</o:Author>
  <o:LastAuthor>calum</o:LastAuthor>
  <o:Revision>35</o:Revision>
  <o:TotalTime>30</o:TotalTime>
  <o:Created>2008-12-18T21:14:00Z</o:Created>
  <o:LastSaved>2008-12-18T21:44:00Z</o:LastSaved>
  <o:Pages>7</o:Pages>
  <o:Words>2648</o:Words>
  <o:Characters>15097</o:Characters>
  <o:Lines>125</o:Lines>
  <o:Paragraphs>35</o:Paragraphs>
  <o:CharactersWithSpaces>17710</o:CharactersWithSpaces>
  <o:Version>12.00</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->
<link rel=themeData href="basics_files/themedata.thmx">
<link rel=colorSchemeMapping href="basics_files/colorschememapping.xml">
<!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:TrackMoves>false</w:TrackMoves>
  <w:TrackFormatting/>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:DoNotPromoteQF/>
  <w:LidThemeOther>EN-GB</w:LidThemeOther>
  <w:LidThemeAsian>X-NONE</w:LidThemeAsian>
  <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:SplitPgBreakAndParaMark/>
   <w:DontVertAlignCellWithSp/>
   <w:DontBreakConstrainedForcedTables/>
   <w:DontVertAlignInTxbx/>
   <w:Word11KerningPairs/>
   <w:CachedColBalance/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
  <m:mathPr>
   <m:mathFont m:val="Cambria Math"/>
   <m:brkBin m:val="before"/>
   <m:brkBinSub m:val="&#45;-"/>
   <m:smallFrac m:val="off"/>
   <m:dispDef/>
   <m:lMargin m:val="0"/>
   <m:rMargin m:val="0"/>
   <m:defJc m:val="centerGroup"/>
   <m:wrapIndent m:val="1440"/>
   <m:intLim m:val="subSup"/>
   <m:naryLim m:val="undOvr"/>
  </m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
  DefSemiHidden="true" DefQFormat="false" DefPriority="99"
  LatentStyleCount="267">
  <w:LsdException Locked="false" Priority="0" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="heading 2"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="heading 3"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 1"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 2"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 3"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 4"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 5"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 6"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 7"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 8"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 9"/>
  <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
  <w:LsdException Locked="false" Priority="10" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Title"/>
  <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
  <w:LsdException Locked="false" Priority="11" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
  <w:LsdException Locked="false" Priority="22" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
  <w:LsdException Locked="false" Priority="20" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
  <w:LsdException Locked="false" Priority="59" SemiHidden="false"
   UnhideWhenUsed="false" Name="Table Grid"/>
  <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
  <w:LsdException Locked="false" Priority="1" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2"/>
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1"/>
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2"/>
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3"/>
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List"/>
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading"/>
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List"/>
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 1"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
  <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
  <w:LsdException Locked="false" Priority="34" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
  <w:LsdException Locked="false" Priority="29" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
  <w:LsdException Locked="false" Priority="30" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 1"/>
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 2"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 2"/>
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 3"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 3"/>
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 4"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 4"/>
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 5"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 5"/>
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 6"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 6"/>
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
  <w:LsdException Locked="false" Priority="19" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
  <w:LsdException Locked="false" Priority="21" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
  <w:LsdException Locked="false" Priority="31" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
  <w:LsdException Locked="false" Priority="32" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
  <w:LsdException Locked="false" Priority="33" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
  <w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
  <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
 </w:LatentStyles>
</xml><![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;
	mso-font-charset:0;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:-1610611985 1107304683 0 0 159 0;}
@font-face
	{font-family:Cambria;
	panose-1:2 4 5 3 5 4 6 3 2 4;
	mso-font-charset:0;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:-1610611985 1073741899 0 0 159 0;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;
	mso-font-charset:0;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:-1610611985 1073750139 0 0 159 0;}
@font-face
	{font-family:Consolas;
	panose-1:2 11 6 9 2 2 4 3 2 4;
	mso-font-charset:0;
	mso-generic-font-family:modern;
	mso-font-pitch:fixed;
	mso-font-signature:-1610611985 1073750091 0 0 159 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-unhide:no;
	mso-style-qformat:yes;
	mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Calibri","sans-serif";
	mso-ascii-font-family:Calibri;
	mso-ascii-theme-font:minor-latin;
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-theme-font:minor-fareast;
	mso-hansi-font-family:Calibri;
	mso-hansi-theme-font:minor-latin;
	mso-bidi-font-family:"Times New Roman";}
h1
	{mso-style-priority:9;
	mso-style-unhide:no;
	mso-style-qformat:yes;
	mso-style-link:"Heading 1 Char";
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	mso-pagination:widow-orphan;
	mso-outline-level:1;
	font-size:24.0pt;
	font-family:"Cambria","serif";
	mso-ascii-font-family:Cambria;
	mso-ascii-theme-font:major-latin;
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-theme-font:minor-fareast;
	mso-hansi-font-family:Cambria;
	mso-hansi-theme-font:major-latin;
	font-weight:bold;}
h2
	{mso-style-priority:9;
	mso-style-unhide:no;
	mso-style-qformat:yes;
	mso-style-link:"Heading 2 Char";
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	mso-pagination:widow-orphan;
	mso-outline-level:2;
	font-size:18.0pt;
	font-family:"Calibri","sans-serif";
	mso-ascii-font-family:Calibri;
	mso-ascii-theme-font:minor-latin;
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-theme-font:minor-fareast;
	mso-hansi-font-family:Calibri;
	mso-hansi-theme-font:minor-latin;
	font-weight:bold;}
h3
	{mso-style-priority:9;
	mso-style-unhide:no;
	mso-style-qformat:yes;
	mso-style-link:"Heading 3 Char";
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	mso-pagination:widow-orphan;
	mso-outline-level:3;
	font-size:13.5pt;
	font-family:"Calibri","sans-serif";
	mso-ascii-font-family:Calibri;
	mso-ascii-theme-font:minor-latin;
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-theme-font:minor-fareast;
	mso-hansi-font-family:Calibri;
	mso-hansi-theme-font:minor-latin;
	font-weight:bold;}
a:link, span.MsoHyperlink
	{mso-style-noshow:yes;
	mso-style-priority:99;
	color:blue;
	text-decoration:underline;
	text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-noshow:yes;
	mso-style-priority:99;
	color:purple;
	text-decoration:underline;
	text-underline:single;}
p
	{mso-style-noshow:yes;
	mso-style-priority:99;
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Calibri","sans-serif";
	mso-ascii-font-family:Calibri;
	mso-ascii-theme-font:minor-latin;
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-theme-font:minor-fareast;
	mso-hansi-font-family:Calibri;
	mso-hansi-theme-font:minor-latin;
	mso-bidi-font-family:"Times New Roman";}
pre
	{mso-style-noshow:yes;
	mso-style-priority:99;
	mso-style-link:"HTML Preformatted Char";
	margin:0cm;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;
	font-size:10.0pt;
	font-family:"Courier New";
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-theme-font:minor-fareast;}
span.Heading1Char
	{mso-style-name:"Heading 1 Char";
	mso-style-priority:9;
	mso-style-unhide:no;
	mso-style-locked:yes;
	mso-style-link:"Heading 1";
	mso-ansi-font-size:24.0pt;
	mso-bidi-font-size:24.0pt;
	font-family:"Cambria","serif";
	mso-ascii-font-family:Cambria;
	mso-ascii-theme-font:major-latin;
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-theme-font:minor-fareast;
	mso-hansi-font-family:Cambria;
	mso-hansi-theme-font:major-latin;
	mso-font-kerning:18.0pt;
	font-weight:bold;}
span.Heading2Char
	{mso-style-name:"Heading 2 Char";
	mso-style-noshow:yes;
	mso-style-priority:9;
	mso-style-unhide:no;
	mso-style-locked:yes;
	mso-style-link:"Heading 2";
	mso-ansi-font-size:13.0pt;
	mso-bidi-font-size:13.0pt;
	font-family:"Cambria","serif";
	mso-ascii-font-family:Cambria;
	mso-ascii-theme-font:major-latin;
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-theme-font:major-fareast;
	mso-hansi-font-family:Cambria;
	mso-hansi-theme-font:major-latin;
	mso-bidi-font-family:"Times New Roman";
	mso-bidi-theme-font:major-bidi;
	color:#4F81BD;
	mso-themecolor:accent1;
	font-weight:bold;}
span.HTMLPreformattedChar
	{mso-style-name:"HTML Preformatted Char";
	mso-style-noshow:yes;
	mso-style-priority:99;
	mso-style-unhide:no;
	mso-style-locked:yes;
	mso-style-link:"HTML Preformatted";
	font-family:Consolas;
	mso-ascii-font-family:Consolas;
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-theme-font:minor-fareast;
	mso-hansi-font-family:Consolas;}
span.Heading3Char
	{mso-style-name:"Heading 3 Char";
	mso-style-noshow:yes;
	mso-style-priority:9;
	mso-style-unhide:no;
	mso-style-locked:yes;
	mso-style-link:"Heading 3";
	mso-ansi-font-size:12.0pt;
	mso-bidi-font-size:12.0pt;
	font-family:"Cambria","serif";
	mso-ascii-font-family:Cambria;
	mso-ascii-theme-font:major-latin;
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-theme-font:major-fareast;
	mso-hansi-font-family:Cambria;
	mso-hansi-theme-font:major-latin;
	mso-bidi-font-family:"Times New Roman";
	mso-bidi-theme-font:major-bidi;
	color:#4F81BD;
	mso-themecolor:accent1;
	font-weight:bold;}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
span.GramE
	{mso-style-name:"";
	mso-gram-e:yes;}
.MsoChpDefault
	{mso-style-type:export-only;
	mso-default-props:yes;
	font-size:10.0pt;
	mso-ansi-font-size:10.0pt;
	mso-bidi-font-size:10.0pt;}
@page Section1
	{size:595.3pt 841.9pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;
	mso-header-margin:35.4pt;
	mso-footer-margin:35.4pt;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 @list l0
	{mso-list-id:1165247009;
	mso-list-template-ids:1809360016;}
@list l0:level1
	{mso-level-number-format:bullet;
	mso-level-text:\F0B7;
	mso-level-tab-stop:36.0pt;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	mso-ansi-font-size:10.0pt;
	font-family:Symbol;}
@list l1
	{mso-list-id:1170296454;
	mso-list-template-ids:1968712834;}
@list l1:level1
	{mso-level-number-format:bullet;
	mso-level-text:\F0B7;
	mso-level-tab-stop:36.0pt;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	mso-ansi-font-size:10.0pt;
	font-family:Symbol;}
@list l2
	{mso-list-id:1989901447;
	mso-list-template-ids:918600164;}
@list l2:level1
	{mso-level-number-format:bullet;
	mso-level-text:\F0B7;
	mso-level-tab-stop:36.0pt;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	mso-ansi-font-size:10.0pt;
	font-family:Symbol;}
ol
	{margin-bottom:0cm;}
ul
	{margin-bottom:0cm;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-priority:99;
	mso-style-qformat:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman","serif";}
</style>
<![endif]--><!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="2050"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1"/>
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-GB link=blue vlink=purple style='tab-interval:36.0pt'>

<div class=Section1>

<h1><span style='mso-fareast-font-family:"Times New Roman"'>Basics <o:p></o:p></span></h1>

<h2><span style='mso-fareast-font-family:"Times New Roman"'>First program <o:p></o:p></span></h2>

<p class=MsoNormal><span style='mso-fareast-font-family:"Times New Roman"'>Enter
the following into a text editor, and save the file as <a href="hello_world.cpp">hello_world.cpp</a>.
<o:p></o:p></span></p>

<pre><o:p>&nbsp;</o:p></pre><pre style='margin-left:36.0pt'>#include &lt;<span
class=SpellE>cppscript</span>&gt;</pre><pre style='margin-left:36.0pt'><o:p>&nbsp;</o:p></pre><pre
style='margin-left:36.0pt'><span class=SpellE><span class=GramE>var</span></span> <span
class=SpellE>script_main</span>(<span class=SpellE>var</span> <span
class=SpellE>args</span>)</pre><pre style='margin-left:36.0pt'>{</pre><pre
style='margin-left:36.0pt'><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>&quot;Hello world!&quot;);</pre><pre
style='margin-left:36.0pt'><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>return</span> 0;</pre><pre style='margin-left:36.0pt'>}</pre>

<p>Next run the program at a command prompt using the <span class=SpellE>cppscript</span>
utility</p>

<pre style='margin-left:30.0pt'>$ <span class=SpellE><span class=GramE>cppscript</span></span> hello_world.cpp</pre><pre
style='margin-left:30.0pt'><o:p>&nbsp;</o:p></pre>

<p class=MsoNormal><span style='mso-fareast-font-family:"Times New Roman"'>The
program should output &quot;Hello world!&quot;<o:p></o:p></span></p>

<h3><span class=GramE><span style='mso-fareast-font-family:"Times New Roman"'>hello_world.cpp</span></span><span
style='mso-fareast-font-family:"Times New Roman"'> explained <o:p></o:p></span></h3>

<p class=MsoNormal><span style='mso-fareast-font-family:"Times New Roman"'>The
first line,<o:p></o:p></span></p>

<pre style='margin-left:36.0pt'><o:p>&nbsp;</o:p></pre><pre style='margin-left:
36.0pt'>#include &lt;<span class=SpellE>cppscript</span>&gt;</pre><pre
style='margin-left:36.0pt'><o:p>&nbsp;</o:p></pre>

<p class=MsoNormal><span class=GramE><span style='mso-fareast-font-family:"Times New Roman"'>is</span></span><span
style='mso-fareast-font-family:"Times New Roman"'> required for all C++Script
programs.&nbsp; This tells the C++ compiler to include the C++Script
functionality.<o:p></o:p></span></p>

<pre><o:p>&nbsp;</o:p></pre><pre style='margin-left:36.0pt'><span class=SpellE><span
class=GramE>var</span></span> <span class=SpellE>script_main</span>(<span
class=SpellE>var</span> <span class=SpellE>args</span>)</pre><pre><o:p>&nbsp;</o:p></pre>

<p class=MsoNormal><span class=GramE><span style='mso-fareast-font-family:"Times New Roman"'>defines</span></span><span
style='mso-fareast-font-family:"Times New Roman"'> a function called <span
class=SpellE><i>script_main</i></span>, that takes one argument (of type <span
class=SpellE><i>var</i></span>, with name <span class=SpellE><i>args</i></span>),
and returns a value of type <i>var</i>.&nbsp; The next line<o:p></o:p></span></p>

<pre style='margin-left:36.0pt'><o:p>&nbsp;</o:p></pre><pre style='margin-left:
36.0pt'>{</pre><pre style='margin-left:36.0pt'><o:p>&nbsp;</o:p></pre>

<p class=MsoNormal><span class=GramE><span style='mso-fareast-font-family:"Times New Roman"'>starts</span></span><span
style='mso-fareast-font-family:"Times New Roman"'> a block of code, and is
required when defining a function.&nbsp; The next line<o:p></o:p></span></p>

<pre><o:p>&nbsp;</o:p></pre><pre style='margin-left:36.0pt'><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>&quot;Hello world!&quot;)</pre><pre><o:p>&nbsp;</o:p></pre>

<p class=MsoNormal><span style='mso-fareast-font-family:"Times New Roman"'>Calls
the function <span class=SpellE><span class=GramE><i>writeln</i></span></span><span
class=GramE><i>(</i></span><i>)</i>, with the string <i>&quot;Hello
world!&quot;</i>.&nbsp; This writes the string to the output.<o:p></o:p></span></p>

<pre><o:p>&nbsp;</o:p></pre><pre style='margin-left:36.0pt'><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>return</span> 0;</pre><pre><o:p>&nbsp;</o:p></pre>

<p class=MsoNormal><span class=GramE><span style='mso-fareast-font-family:"Times New Roman"'>returns</span></span><span
style='mso-fareast-font-family:"Times New Roman"'> the value 0 from the <span
class=SpellE><i>script_main</i></span> function.&nbsp; This is the value which
the program returns to the shell.<o:p></o:p></span></p>

<pre><o:p>&nbsp;</o:p></pre><pre style='margin-left:36.0pt'>}</pre><pre
style='margin-left:36.0pt'><o:p>&nbsp;</o:p></pre>

<p class=MsoNormal><span class=GramE><span style='mso-fareast-font-family:"Times New Roman"'>Ends
the function definition of <span class=SpellE><i>script_main</i></span>.</span></span><span
style='mso-fareast-font-family:"Times New Roman"'><o:p></o:p></span></p>

<pre><o:p>&nbsp;</o:p></pre><pre style='margin-left:36.0pt'>$ <span
class=SpellE><span class=GramE>cppscript</span></span> hello_world.cpp</pre><pre><o:p>&nbsp;</o:p></pre>

<p class=MsoNormal><span class=GramE><span style='mso-fareast-font-family:"Times New Roman"'>Runs
the <span class=SpellE><i>cppscript</i></span><i> </i>program, passing it the
file name hello_world.cpp.</span></span><span style='mso-fareast-font-family:
"Times New Roman"'>&nbsp; The <span class=SpellE><i>cppscript</i></span><i> </i>program
calls the C++ compiler (e.g. g++) to compile <i>hello.cpp</i> and produces the <i>hello</i>
executable (or <i>hello.exe</i>).&nbsp; Finally <span class=SpellE><i>cppscript</i></span>
executes the program, which outputs &quot;Hello world!<span class=GramE>&quot;.</span><o:p></o:p></span></p>

<h3><span class=GramE><span style='mso-fareast-font-family:"Times New Roman"'>main(</span></span><span
style='mso-fareast-font-family:"Times New Roman"'>) and <span class=SpellE>script_main</span>()<o:p></o:p></span></h3>

<p>C and C++ programs require a function called <span class=GramE><i>main(</i></span><i>)</i>
to mark the start of the program.&nbsp;</p>

<p>This is less suitable for C++Script because it uses native types (e.g.
char**), and it doesn't catch exceptions.&nbsp; Therefore, C++Script provides a
<span class=GramE><i>main(</i></span><i>)</i> function that catches exceptions,
and calls a <span class=SpellE><i>script_main</i></span><i>()</i> function
instead.&nbsp; C++Script can use either <span class=GramE><i>main(</i></span><i>)</i>
or <span class=SpellE><i>script_main</i></span><i>().</i></p>

<h2><span style='mso-fareast-font-family:"Times New Roman"'>Variables<o:p></o:p></span></h2>

<p>C++Script uses a single variable type, called <i>var.</i>&nbsp; A <span
class=SpellE>var</span> can take on any type of value, such as: </p>

<ul type=disc>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l0 level1 lfo1;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>integers <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l0 level1 lfo1;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>floating point values (doubles) <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l0 level1 lfo1;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>strings (wide and narrow) <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l0 level1 lfo1;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>chars (wide and narrow) <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l0 level1 lfo1;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>Booleans (true/false) <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l0 level1 lfo1;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>containers (arrays, maps, lists etc) <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l0 level1 lfo1;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>objects and methods <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l0 level1 lfo1;tab-stops:list 36.0pt'><span class=SpellE><span
     style='mso-fareast-font-family:"Times New Roman"'>functors</span></span><span
     style='mso-fareast-font-family:"Times New Roman"'> (functions or closures)
     <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l0 level1 lfo1;tab-stops:list 36.0pt'><span class=SpellE><span
     style='mso-fareast-font-family:"Times New Roman"'>iterators</span></span><span
     style='mso-fareast-font-family:"Times New Roman"'> <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l0 level1 lfo1;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>null&nbsp;<i> </i><o:p></o:p></span></li>
</ul>

<p>Whilst in a normal C++ program you need to declare the type of the variable,
in C++Script you just use the <span class=SpellE><i>var</i></span><i> </i>type
which holds whatever you assign to it. </p>

<p>Like most scripting languages, <span class=SpellE><i>var</i></span><i> </i>can
hold values of any type. </p>

<p>e.g. (<a href="basic_types.cpp">basic_types.cpp</a>) </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt;</pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> <span class=SpellE>script_main</span>(<span
class=SpellE>var</span>)</pre><pre>{</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>var</span></span> a=12, b=3.14, c=&quot;Hi&quot;;</pre><pre> &nbsp;<span style='mso-spacerun:yes'>&nbsp; </span>a=true;</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>a); </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=GramE>return</span> 0;</pre><pre>}</pre></blockquote>

<p>Obviously <span class=SpellE><i>var</i>s</span> do have types at run-time,
but they are just not declared in the program at compile-time.</p>

<h2><span style='mso-fareast-font-family:"Times New Roman"'>Null <o:p></o:p></span></h2>

<p>Uninitialized variables (that have not had a value assigned to them) take on
the null value. </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span
class=SpellE><span class=GramE>var</span></span> x; </pre><pre><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>x);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
// Output: null </pre></blockquote>

<p>The null value is a perfectly legitimate value.&nbsp; The null value
converts to the string &quot;null&quot;, the integer 0, or the Boolean false. </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span
class=SpellE><span class=GramE>var</span></span> x; </pre><pre><span
class=GramE>if(</span>!x) <span class=SpellE>writeln</span>(&#8220;x is false&#8221;); </pre></blockquote>

<p class=MsoNormal><span style='mso-fareast-font-family:"Times New Roman"'>The
constant <i>null </i>has the null value. &nbsp;<span class=GramE>e.g.</span><o:p></o:p></span></p>

<pre style='margin-left:30.0pt'><o:p>&nbsp;</o:p></pre><pre style='margin-left:
30.0pt'>x=&quot;hello&quot;;</pre><pre style='margin-left:30.0pt'><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>x);</pre><pre
style='margin-left:30.0pt'>x=null;</pre><pre style='margin-left:30.0pt'><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>x);&nbsp;&nbsp;&nbsp; // &quot;null&quot;</pre>

<h2><span style='mso-fareast-font-family:"Times New Roman"'>Operators <o:p></o:p></span></h2>

<p>Like normal C++ variables, <span class=SpellE>var</span> values support the
entire set of operators. &nbsp;Thus you can perform arithmetic on <span
class=SpellE>var</span> values, and use <span class=SpellE>var</span> values
just like any other built in type in C++.</p>

<p><span class=SpellE><span class=GramE><i>var</i></span></span> performs
automatic conversion.&nbsp; Usually the second operand is converted to the type
of the first operand.&nbsp; For example if you add an integer to a string, then
the second operand (the integer) gets converted to a string.&nbsp; On the other
hand, if you add a string to an integer, then the second operand (the string)
gets converted to an integer.&nbsp; The following example (<a
href="operators.cpp">operators.cpp</a>) illustrates this. </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt;</pre><pre><o:p>&nbsp;</o:p></pre><pre><span
lang=SV style='mso-ansi-language:SV'>var script_main(var) <o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'>{ <o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span>var x=12, y=4, z=&quot;10&quot;; <o:p></o:p></span></pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>x-y);&nbsp;&nbsp;&nbsp;&nbsp; // 8</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>x+&quot;8&quot;);&nbsp;&nbsp; // 20</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>z+20);&nbsp;&nbsp;&nbsp; // 1020</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>return</span> 0; </pre><pre>}</pre></blockquote>

<p>Some operations are not supported.&nbsp; For example attempting to subtract
two strings fails (<a href="subtract_strings.cpp">subtract_strings.cpp</a>),
throws an exception: </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt; </pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> <span class=SpellE>script_main</span>(<span
class=SpellE>var</span>) </pre><pre>{ </pre><pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>&quot;We are about to throw an exception&quot;); </pre><pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
class=SpellE><span class=GramE>var</span></span><span class=GramE>(</span>&quot;<span
class=SpellE>abc</span>&quot;) - <span class=SpellE>var</span>(&quot;def&quot;); </pre><pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
class=GramE>return</span> 0; </pre><pre>}</pre></blockquote>

<h2><span style='mso-fareast-font-family:"Times New Roman"'>Converting between
types<o:p></o:p></span></h2>

<p>It is straightforward to convert between C++ values and <i>var</i>.</p>

<p>Usually C++ values are implicitly converted to <span class=SpellE>var</span>
as needed.&nbsp; <span lang=SV style='mso-ansi-language:SV'>e.g.<o:p></o:p></span></p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span lang=SV
style='mso-ansi-language:SV'>var x = 12;<o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'>var y = x + 15;<o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'>var z = var(&#8220;12&#8221;)+21; // &#8220;1221&#8221;<o:p></o:p></span></pre></blockquote>

<p>The <span class=SpellE><i>var</i></span><i> </i>class has the following
methods to convert the <span class=SpellE>var</span> into a C++ type: </p>

<ul type=disc>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l1 level1 lfo2;tab-stops:list 36.0pt'><span class=SpellE><i><span
     style='mso-fareast-font-family:"Times New Roman"'>int</span></i></span><i><span
     style='mso-fareast-font-family:"Times New Roman"'> <span class=SpellE>var</span>::<span
     class=SpellE>as_int</span>() const &#8211;</span></i><span
     style='mso-fareast-font-family:"Times New Roman"'> convert to <span
     class=SpellE>int</span> <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l1 level1 lfo2;tab-stops:list 36.0pt'><span class=SpellE><i><span
     style='mso-fareast-font-family:"Times New Roman"'>bool</span></i></span><i><span
     style='mso-fareast-font-family:"Times New Roman"'> <span class=SpellE>var</span>::
     <span class=SpellE>as_bool</span>() const &#8211;</span></i><span
     style='mso-fareast-font-family:"Times New Roman"'> convert to <span
     class=SpellE>bool</span> <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l1 level1 lfo2;tab-stops:list 36.0pt'><i><span style='mso-fareast-font-family:
     "Times New Roman"'>std::string <span class=SpellE>var</span>:: <span
     class=SpellE>as_string</span>() const &#8211;</span></i><span
     style='mso-fareast-font-family:"Times New Roman"'> convert to std::string <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l1 level1 lfo2;tab-stops:list 36.0pt'><i><span style='mso-fareast-font-family:
     "Times New Roman"'>std::<span class=SpellE>wstring</span> <span
     class=SpellE>var</span>:: <span class=SpellE>as_wstring</span>() const
     &#8211;</span></i><span style='mso-fareast-font-family:"Times New Roman"'>
     convert to std::<span class=SpellE>wstring</span> <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l1 level1 lfo2;tab-stops:list 36.0pt'><i><span style='mso-fareast-font-family:
     "Times New Roman"'>double <span class=SpellE>var</span>:: <span
     class=SpellE>as_double</span>() const &#8211;</span></i><span
     style='mso-fareast-font-family:"Times New Roman"'> convert to double<i> </i><o:p></o:p></span></li>
</ul>

<p class=MsoNormal><span class=GramE><span style='mso-fareast-font-family:"Times New Roman"'>e.g.</span></span><span
style='mso-fareast-font-family:"Times New Roman"'><o:p></o:p></span></p>

<pre><o:p>&nbsp;</o:p></pre><pre style='margin-left:36.0pt'><span lang=SV
style='mso-ansi-language:SV'>int i = x.as_int();<o:p></o:p></span></pre><pre
style='margin-left:36.0pt'><span class=GramE>double</span> j = <span
class=SpellE>y.as_double</span>();</pre>

<p>These functions will do their best to perform the conversion, for example <span
class=SpellE><span class=GramE><i>var</i></span></span><span class=GramE><i>(</i></span><i>&#8220;1.3e2&#8221;).<span
class=SpellE>as_int</span>()</i> will return 1, since it tries to parse the
string as an integer. </p>

<p>Conversion can also convert between different types of <i>var.</i>&nbsp; <span
lang=SV style='mso-ansi-language:SV'>e.g. <o:p></o:p></span></p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span lang=SV
style='mso-ansi-language:SV'>var a = &quot;1234&quot;; <o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'>var b = a.as_int();<o:p></o:p></span></pre></blockquote>

<p><span class=SpellE><span class=GramE><i>var</i></span></span> has an implicit
conversion to <span class=SpellE>bool</span>.&nbsp; That means that you can put
<span class=SpellE><i>var</i></span> into conditions, such as <i>if</i>
statements and <i>while</i> loops. </p>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>Comparisons<o:p></o:p></span></h3>

<p>The C++ comparison operators (&lt;, &gt;, ==<span class=GramE>, !</span>=,
&lt;=, &gt;=) work on <i>var</i>.<br>
<br>
All different <span class=SpellE><i>var</i></span><i> </i>types can be
compared.&nbsp; <span class=SpellE><span class=GramE>vars</span></span> are
first compared on type, then by value.&nbsp; Conversions are never performed
for comparison (since comparison should be symmetrical).<br>
<br>
Comparison may not work quite as expected, e.g. integers are always less than
doubles, no matter what their value.&nbsp; Also all narrow strings are less
than wide strings, no matter what the contents of the string.&nbsp;
Essentially, each <span class=SpellE>var</span> has a built-in type, which is
compared prior to comparing the contents of the var.&nbsp; This is because
sometimes a comparison makes no sense (e.g. a list an <span class=SpellE>an</span>
integer), or could be ambiguous (<span class=SpellE>e.g</span> a double and an <span
class=SpellE>int</span> - does this mean integer comparison or double
comparison), or a string and an <span class=SpellE>int</span> (does this mean
parse the string as an <span class=SpellE>int</span>, or convert the <span
class=SpellE>int</span> to a string?). </p>

<p>All <a
href="../../../../trunk/Projects/Current/cppscript/dist/docs/containers.html">containers</a>
(with the exception of strings), compare on object address.&nbsp; This is
because a <span class=SpellE>lexographic</span> comparison might result in an
infinite loop.&nbsp; <i>std::<span class=SpellE>lexographic_<span class=GramE>compare</span></span><span
class=GramE>(</span>)</i> is available if that is indeed the intended
comparison method.</p>

<h2><span style='mso-fareast-font-family:"Times New Roman"'>Variable scope<o:p></o:p></span></h2>

<p class=MsoNormal><span style='mso-fareast-font-family:"Times New Roman"'>In
C++, the end of the block (a closing curly brace) marks the end of the lexical
scope of a variable, meaning that variable names are only local to the block in
which they are declared. &nbsp;In standard C++, variables are destroyed at the
end of the block, but in C++Script, <span class=SpellE><i>vars</i></span> are
destroyed by the garbage collector.<br>
<br>
In C++Script, <span class=SpellE><i>vars</i></span> usually share the
underlying data (with the exception of integers and doubles).&nbsp; Copying a <span
class=SpellE>var</span> does not copy the underlying data.<br>
<br>
e.g. (<a href="var_copy.cpp">var_copy.cpp</a>)<o:p></o:p></span></p>

<p class=MsoNormal><span style='mso-fareast-font-family:"Times New Roman"'><o:p>&nbsp;</o:p></span></p>

<pre style='margin-left:36.0pt'>#include &lt;<span class=SpellE>cppscript</span>&gt;</pre><pre
style='margin-left:36.0pt'><o:p>&nbsp;</o:p></pre><pre style='margin-left:36.0pt'><span
class=SpellE><span class=GramE>var</span></span> <span class=SpellE>script_main</span>(<span
class=SpellE>var</span>)</pre><pre style='margin-left:36.0pt'>{</pre><pre
style='margin-left:36.0pt'>&nbsp;&nbsp;&nbsp; <span class=SpellE><span
class=GramE>var</span></span> a = &quot;<span class=SpellE>abc</span>&quot;, b=a;</pre><pre
style='margin-left:36.0pt'> &nbsp;<span style='mso-spacerun:yes'>&nbsp; </span>b += &quot;def&quot;;</pre><pre
style='margin-left:36.0pt'><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>a);&nbsp;&nbsp;&nbsp; // <span
class=SpellE>abcdef</span></pre><pre style='margin-left:36.0pt'> &nbsp;<span style='mso-spacerun:yes'>&nbsp; </span><span
class=GramE>return</span> 0;</pre><pre style='margin-left:36.0pt'>}</pre>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>Cloning<o:p></o:p></span></h3>

<p>A <span class=SpellE>var</span> can be <i>cloned,</i> meaning that it creates
a copy of the value.&nbsp; The unary + operator <span class=GramE>creates</span>
a clone of a var. </p>

<p>This means that the two values (the original and the copy) can be modified
independently.&nbsp; e.g. (<a href="var_clone.cpp">var_clone.cpp</a>)</p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt;</pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> <span class=SpellE>script_main</span>(<span
class=SpellE>var</span>)</pre><pre>{</pre><pre>&nbsp;&nbsp;&nbsp; <span
class=SpellE><span class=GramE>var</span></span> a = &quot;<span class=SpellE>abc</span>&quot;, b=+a;</pre><pre>&nbsp;&nbsp;&nbsp; b += &quot;def&quot;;&nbsp;&nbsp;&nbsp;</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>a);&nbsp;&nbsp;&nbsp; // <span
class=SpellE>abc</span></pre><pre>&nbsp;&nbsp;&nbsp; <span class=GramE>return</span> 0;</pre><pre>}</pre></blockquote>

<p>Cloning is supported on all <span class=SpellE>var</span> types.&nbsp; Some
types (such as <span class=SpellE>ints</span>) are not shared, so cloning has
no effect, just like unary +.&nbsp; Cloning of containers (arrays etc) performs
a shallow copy, meaning that whilst the array itself is different, the copied
contents are still shared. </p>

<h2><span style='mso-fareast-font-family:"Times New Roman"'>Comments <o:p></o:p></span></h2>

<p>Comments can be written in a C style (between /* and */) or C++ style (after
//). </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span
class=SpellE><span class=GramE>var</span></span> x = f(f(g));&nbsp;&nbsp;&nbsp; // Ensure that the <span
class=SpellE>sprogit</span> is fused</pre></blockquote>

<h2><span style='mso-fareast-font-family:"Times New Roman"'>Control flow <o:p></o:p></span></h2>

<p>C++ (and therefore C++Script) programs are organised into functions, and the
statements in each function are executed sequentially.&nbsp; You can change the
sequence (the control flow) using <i>if</i>, <i>for</i>, <i>while</i>, <span
class=SpellE><i>goto</i></span> (not recommended), exceptions and the new <span
class=SpellE><i>foreach</i></span> macro.</p>

<p>If-statements evaluate a condition, and execute either the
&#8220;then&#8221; part or the &#8220;else&#8221; part.&nbsp; If there is more
than one statement in the &#8220;then&#8221; or &#8220;else&#8221; parts, then
the statements must be grouped using curly braces.&nbsp; <span class=GramE>e.g.</span>
</p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span
class=GramE>if(</span> <span class=SpellE>args.size</span>() != 3 )</pre><pre>{</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span> &quot;Please supply 3 arguments&quot; );</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>return</span> 10;</pre><pre>}</pre><pre><span class=GramE>else</span></pre><pre>{</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span> &quot;Thank you&quot; );</pre><pre>}</pre></blockquote>

<p>The curly brackets are optional if they contain a single statement.</p>

<p>While-statements execute the body of the loop until the condition is
false.&nbsp; <span class=GramE>e.g. (<a href="while.cpp">while.cpp</a>).</span>
</p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt;</pre><pre><o:p>&nbsp;</o:p></pre><pre><span
lang=SV style='mso-ansi-language:SV'>var script_main(var args)<o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'>{<o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>var i=0;<o:p></o:p></span></pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>while(</span><span class=SpellE>i</span>++&lt;10) <span
class=SpellE>writeln</span>(<span class=SpellE>i</span>);</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>return</span> 0;</pre><pre>}</pre></blockquote>

<p>Do-while-statements execute the body of the loop until the condition is
false, but execute the loop at least once. </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>&quot;Enter a number&quot;); </pre><pre><span
class=SpellE><span class=GramE>var</span></span> m;</pre><pre><span
class=GramE>do</span> </pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span>m = <span
class=SpellE><span class=GramE>readln</span></span><span class=GramE>(</span>).<span
class=SpellE>as_int</span>();</pre><pre>}</pre><pre><span class=GramE>while(</span> m==0 );</pre></blockquote>

<p>For-statements are a lot like while loops, except that they specify an <span
class=SpellE>initializer</span> (the initial state of the loop), the condition
(what must be true to continue looping), and <span class=GramE>an</span>
increment (move on to the next item in the loop).&nbsp; The general structure
is as follows: </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span
class=GramE>for(</span><span class=SpellE>initializer</span>; condition; increment)</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>body</span></pre></blockquote>

<p><span lang=SV style='mso-ansi-language:SV'>e.g. <o:p></o:p></span></p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span lang=SV
style='mso-ansi-language:SV'>for(var i=0; i&lt;10; ++i) <o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'>{ <o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span>writeln(i);<o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'>}<o:p></o:p></span></pre></blockquote>

<h3><span class=SpellE><span class=GramE><span style='mso-fareast-font-family:
"Times New Roman"'>foreach</span></span></span><span style='mso-fareast-font-family:
"Times New Roman"'> <o:p></o:p></span></h3>

<p>C++Script provides a <span class=SpellE><i>foreach</i></span><i> </i>macro
to match the facilities in other scripting languages.&nbsp; This makes it much
simpler to loop through containers. </p>

<p>The first parameter to the <span class=SpellE><i>foreach</i></span><i> </i>macro
is the loop variable, and the second parameter is the container.&nbsp; This
example (<a href="foreach1.cpp">foreach1.cpp</a>) loops through all of the
arguments to the program, and displays a message. </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt; </pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> <span class=SpellE>script_main</span>(<span
class=SpellE>var</span> <span class=SpellE>args</span>) </pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=SpellE><span class=GramE>foreach</span></span><span class=GramE>(</span><span
class=SpellE>i</span>, <span class=SpellE>args</span>) <span class=SpellE>writeln</span>(&quot;Hello &quot;+<span
class=SpellE>i</span>); </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=GramE>return</span> 0; </pre><pre>} </pre></blockquote>

<p>The <span class=GramE><i>range(</i></span><i>)</i> function creates a range
which can then be iterated using <span class=SpellE>foreach</span>.&nbsp; This
example (<a href="range1.cpp">range1.cpp</a>) displays multiplication tables. </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt; </pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> <span class=SpellE>script_main</span>(<span
class=SpellE>var</span>) </pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=SpellE><span class=GramE>foreach</span></span><span class=GramE>(</span> <span
class=SpellE>i</span>, range(1,12) ) </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span>{</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>foreach</span></span><span class=GramE>(</span> j, range(1,12) ) </pre><pre><span
lang=SV style='mso-ansi-language:SV'><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>writeln( &quot;&quot; + i + &quot; * &quot; + j + &quot; = &quot; + i*j ); <o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span></span>}</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>return</span> 0; </pre><pre>} </pre></blockquote>

<h2><span style='mso-fareast-font-family:"Times New Roman"'>Functions <o:p></o:p></span></h2>

<p>Functions are named blocks of code.&nbsp; One of the reasons for splitting a
program up into functions is to make the whole thing more manageable.&nbsp;
Functions shouldn't contain more than 20 or so lines of code - obviously rules
can be broken, but splitting functionality up into small individually-testable
units is a good thing.</p>

<p>Functions have arguments (inputs), and a return value (output). </p>

<h3><span class=GramE><span style='mso-fareast-font-family:"Times New Roman"'>main(</span></span><span
style='mso-fareast-font-family:"Times New Roman"'>) and <span class=SpellE>script_main</span>()
<o:p></o:p></span></h3>

<p>These functions are called when the C++Script program starts. </p>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>Library functions <o:p></o:p></span></h3>

<p>We&#8217;ve already met the library function <span class=SpellE><span
class=GramE><i>writeln</i></span></span><span class=GramE><i>(</i></span><i>)</i>
&#8211; it displays the value followed by a new line.&nbsp; There are many more
functions described throughout the tutorial and in the <a href="#Reference">reference</a>
section.</p>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>C and C++ functions
<o:p></o:p></span></h3>

<p>C++Script can call C and C++ functions.&nbsp; Like normal C++, you must <i>#include</i>
the appropriate header file at the beginning of the .<span class=SpellE>cpp</span>
file, and link with the appropriate library.</p>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>User-defined
functions <o:p></o:p></span></h3>

<p>The general form of a function definition is </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span lang=SV
style='mso-ansi-language:SV'>var fn(var arg1, var arg2, var arg3 ...) <o:p></o:p></span></pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span>// Function body </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=GramE>return</span> ... ; </pre><pre>} </pre></blockquote>

<p><span class=GramE>where</span> fn is the function name, and <i>arg1</i>, <i>arg2</i>
etc are the arguments to the function.&nbsp; A function can have no arguments,
in which case the function is written </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span
class=SpellE><span class=GramE>var</span></span> fn() </pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span>// ...</pre><pre>} </pre></blockquote>

<p>It is not possible to define functions inside functions (&quot;nested
functions&quot;) in C++. </p>

<p>C++ functions are &quot;overloaded&quot;. This means that several functions
can have the same name but can have different arguments.&nbsp; The C++ compiler
selects the most appropriate function.</p>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>Return value <o:p></o:p></span></h3>

<p>In C++Script, the value returned from functions is a&nbsp;<i>var</i>.&nbsp;
If a function does not return anything at all, the return type can be <i>void</i>,
and the function is written </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span
class=GramE>void</span> fn( /* ... */ ) </pre><pre>{ </pre><pre>} </pre></blockquote>

<p>A non-void function returns a value using the return statement.&nbsp; This
is written</p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span
class=GramE>return</span> X; </pre></blockquote>

<p><span class=GramE>where</span> X is the value to be returned.&nbsp; The <span
class=SpellE><i>script_<span class=GramE>main</span></i></span><span
class=GramE><i>(</i></span><i>)</i> function returns an integer to the shell.</p>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>Calling functions <o:p></o:p></span></h3>

<p>We have already seen how to call <span class=SpellE><span class=GramE><i>writeln</i></span></span><span
class=GramE><i>(</i></span><i>)</i>.&nbsp; A function is called by supplying
the arguments to the function in round brackets after the function name,
separated by commas. The number of arguments must match the number of arguments
in the function definition, or the compiler will give an error. </p>

<p>This example shows a function being declared and then called.&nbsp; (<a
href="function1.cpp">function1.cpp</a>)</p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt; </pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> add(<span class=SpellE>var</span> a, <span
class=SpellE>var</span> b) { return <span class=SpellE>a+b</span>; } </pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> <span class=SpellE>script_main</span>(<span
class=SpellE>var</span>) </pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span> add(2,3) ); // 5</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>return</span> 0;</pre><pre>}</pre></blockquote>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>Function
declarations <o:p></o:p></span></h3>

<p>C++ has a rule whereby functions must be declared or defined before they are
called.&nbsp; In a single C++ file this is not a problem because you can almost
always organise the functions in such a way as to satisfy this rule.&nbsp; (The
exception to this is mutually recursive functions).&nbsp; With multiple .<span
class=SpellE>cpp</span> files, or when you call functions in a library, you
must <i>forward-declare</i> the functions, which is the same as a function
definition but with a semicolon instead of the function body.&nbsp; Normally
you put the forward-declarations in a header file (.h or .<span class=SpellE>hpp</span>
file) which you #include into all of the .<span class=SpellE>cpp</span> files
that need it.</p>

<p>This example shows a declaration of a function. (<a
href="function_declaration.cpp">function_declaration.cpp</a>)</p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt;</pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> f(); </pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> <span class=SpellE>script_main</span>(<span
class=SpellE>var</span>) </pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=GramE>return</span> f();</pre><pre>} </pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> f() </pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=GramE>return</span> 2; </pre><pre>}</pre></blockquote>

<h3><span class=SpellE><span style='mso-fareast-font-family:"Times New Roman"'>Functors</span></span><span
style='mso-fareast-font-family:"Times New Roman"'> <o:p></o:p></span></h3>

<p>A <span class=SpellE><i>functor</i></span><i> </i>is a <span class=SpellE>var</span>
that acts as a function.&nbsp; <span lang=SV style='mso-ansi-language:SV'>Any
function of the form <o:p></o:p></span></p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span lang=SV
style='mso-ansi-language:SV'>var fn(var, var, var ...) <o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'>void fn(var, var, var, ...) <o:p></o:p></span></pre></blockquote>

<p><span class=GramE>can</span> be stored in a <i>var</i>. &nbsp;The <span
class=SpellE>var</span> can then be called as a function, as follows: (<a
href="functor.cpp">functor.cpp</a>)</p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt; </pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> sum(<span class=SpellE>var</span> a, <span
class=SpellE>var</span> b) { return <span class=SpellE>a+b</span>; } </pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> <span class=SpellE>script_main</span>(<span
class=SpellE>var</span>) </pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=SpellE><span class=GramE>var</span></span> <span class=SpellE>sum_fn</span> = sum; </pre><pre><span style='mso-spacerun:yes'>&nbsp;</span><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;</span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span> <span
class=SpellE>sum_fn</span>(2,3) ); // 5</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>return</span> 0;</pre><pre>}</pre></blockquote>

<p>See <a href="oop.html">OOP</a> for further explanation of <span
class=SpellE>functors</span>.&nbsp; </p>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>Variable number of
arguments<o:p></o:p></span></h3>

<p>C++ does not have very good support for variable numbers of arguments.&nbsp;
Things are a little bit better in C++Script.&nbsp; You can have variable
arguments either by passing an array to the function, or by using the <span
class=SpellE><span class=GramE><i>varargs</i></span></span><span class=GramE><i>(</i></span><i>)</i>
function which automatically creates the array from variable numbers of
arguments.&nbsp; e.g. (<a href="varargs.cpp">varargs.cpp</a>)</p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt;</pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=GramE>void</span> <span class=SpellE>greet_list</span>(<span
class=SpellE>var</span> greeting, <span class=SpellE>var</span> people) </pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=SpellE><span class=GramE>foreach</span></span><span class=GramE>(</span><span
class=SpellE>i</span>, people) <span class=SpellE>writeln</span>(greeting + &quot; &quot; + <span
class=SpellE>i</span>); </pre><pre>}</pre><pre><o:p>&nbsp;</o:p></pre><pre><span
lang=SV style='mso-ansi-language:SV'>var script_main(var args)<o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'>{<o:p></o:p></span></pre><pre><span
lang=SV style='mso-ansi-language:SV'><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>var hello = varargs( bind(greet_list, &quot;Hello&quot;) );<o:p></o:p></span></pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>hello(</span>&quot;cat&quot;, &quot;dog&quot;, &quot;horse&quot;);</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>return</span> 0;</pre><pre>}</pre></blockquote>

<h2><span style='mso-fareast-font-family:"Times New Roman"'>Exceptions <o:p></o:p></span></h2>

<p>An exception is an event indicating an unexpected failure.&nbsp; Types of
failure that might cause exceptions are: </p>

<ul type=disc>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l2 level1 lfo3;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>Running out of memory <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l2 level1 lfo3;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>Calling a function with the wrong number of arguments <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l2 level1 lfo3;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>Passing an invalid argument, such as a negative index <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l2 level1 lfo3;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>Calling a method that does not exist <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l2 level1 lfo3;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>Performing an operation that is not valid for the <span
     class=SpellE>var</span> type <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l2 level1 lfo3;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>User-generated exceptions <o:p></o:p></span></li>
 <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
     mso-list:l2 level1 lfo3;tab-stops:list 36.0pt'><span style='mso-fareast-font-family:
     "Times New Roman"'>etc&nbsp; <o:p></o:p></span></li>
</ul>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>Catching exceptions
<o:p></o:p></span></h3>

<p>Exceptions thrown from C++Script have type <span class=SpellE>var</span>, and
can be caught using try-catch statement: </p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre><span
class=GramE>try</span> </pre><pre>{ </pre><pre>&nbsp;&nbsp;&nbsp;&nbsp;// Code which might throw the exception </pre><pre>} </pre><pre><span
class=GramE>catch(</span><span class=SpellE>var</span> ex) </pre><pre>{ </pre><pre>&nbsp;&nbsp;&nbsp;&nbsp;// Handle exception </pre><pre>} </pre></blockquote>

<p>Naturally you can combine this with other C++ exception handling.&nbsp;
Unlike C++, the <span class=GramE><i>main(</i></span><i>)</i> function
implemented by C++Script catches and reports exceptions.</p>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>Throwing exceptions
<o:p></o:p></span></h3>

<p>You can throw an exception at any time by writing <i>throw X</i>; where <i>X</i>
is the value you want to throw.&nbsp; In C++Script, there is one type of
exception (<span class=SpellE><i>var</i></span>).&nbsp; The helper class <i>exception</i>
constructs an exception <i>var</i>.&nbsp; e.g. (<a href="exception.cpp">exception.cpp</a>)</p>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>#include &lt;<span
class=SpellE>cppscript</span>&gt; </pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> compute() </pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=GramE>throw</span> exception(&quot;<span class=SpellE>compute_failure</span>&quot;, &quot;Not implemented&quot;);</pre><pre>}</pre><pre><o:p>&nbsp;</o:p></pre><pre><span
class=SpellE><span class=GramE>var</span></span> <span class=SpellE>script_main</span>(<span
class=SpellE>var</span>) </pre><pre>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=GramE>try</span> </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=GramE>compute(</span>); </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span>} </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=GramE>catch(</span><span class=SpellE>var</span> ex) </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;</span>{ </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=GramE>if(</span> <span class=SpellE>ex.class_name</span>() == &quot;<span
class=SpellE>compute_failure</span>&quot; )</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span
class=SpellE><span class=GramE>writeln</span></span><span class=GramE>(</span>&quot;The computation failed because &quot; + ex[&quot;text&quot;]);</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span
class=GramE>else</span> </pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class=GramE>throw</span>; // Re-throws the exception - caught in main()</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>}</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=GramE>return</span> 0;</pre><pre>}</pre></blockquote>

<p>C++Script's exception handling is limited because you can't switch on type,
so you have to check <span class=SpellE><i>var</i></span><i>::<span
class=SpellE>class_<span class=GramE>name</span></span><span class=GramE>(</span>)</i>.</p>

<h3><span style='mso-fareast-font-family:"Times New Roman"'>Finally<o:p></o:p></span></h3>

<p>It is important that your program is able to recover cleanly whenever
exceptions are thrown. &nbsp;Recovering from exceptions is a topic in itself,
however the approach that C++ often uses is to use <i>RAII, </i>have cleanup
code in its <i>destructor, </i>or use <span class=SpellE><i>scopeguard</i></span><i>.
&nbsp;</i>Other languages have <i>finally </i>and <i>using </i>statements.
&nbsp;If these words don't mean very much to you then don't worry. &nbsp;The
important concept is the idea that some code is <span class=GramE>executed
&nbsp;that</span> cleans up whatever needs to be cleaned up (e.g. closing a
file, unlocking a lock, terminating a network connection).</p>

<p>C++Script has a garbage collector, which means that you don't need to clean
up memory, but there are other resources which may need cleaning up. &nbsp;The
garbage collector will clean up certain resources like files, but much later
than you intended if your code fails. &nbsp;For example</p>

<pre style='margin-left:30.0pt'><span class=SpellE><span class=GramE>var</span></span> f = <span
class=SpellE>write_file</span>(&quot;data.txt&quot;);</pre><pre
style='margin-left:30.0pt'><span class=SpellE>write_data_to_<span class=GramE>file</span></span><span
class=GramE>(</span>f);&nbsp;&nbsp;&nbsp; // May throw an exception</pre><pre
style='margin-left:30.0pt'><span class=GramE>f[</span>&quot;close&quot;]();</pre>

<p>What you want is for <span class=GramE><i>f[</i></span><i>&quot;close&quot;]()</i>
to be called even if <span class=SpellE><i>write_data_to_file</i></span><i>()</i>
throws an exception. &nbsp;You can wrap <span class=SpellE><i>write_data_to_<span
class=GramE>file</span></i></span><span class=GramE><i>(</i></span><i>)</i> in
a try-catch block, but it is neater to use a <i>finally</i> macro to execute <i>f[&quot;close&quot;]()</i>
at the end of the block, even if <span class=SpellE><i>write_data_to_file</i></span><i>()</i>
throws an exception. &nbsp;<span class=GramE>e.g.</span></p>

<pre style='margin-left:30.0pt'><span class=SpellE><span class=GramE>var</span></span> f = <span
class=SpellE>write_file</span>(&quot;data.txt&quot;);</pre><pre
style='margin-left:30.0pt'><span class=GramE>finally(</span>f[&quot;close&quot;]);</pre><pre
style='margin-left:30.0pt'><span class=SpellE>write_data_to_file</span>(f);</pre>

<p>The <i>finally </i>macro takes a <span class=SpellE>functor</span> and
executes it at the end of the block.&nbsp; See e.g. <a href="finally.cpp">finally.cpp</a>.</p>

</div>

</body>

</html>
